//定义接口
interface FullName{
    firstName:string,
    lastName:string,
    age?:number,
    [propsName:string]:any //配置任意属性  键必须是字符串类型：值为任意类型
}

function printName(info:FullName):void{
    if(info.age){
        console.log(`我叫：${info.firstName},${info.lastName}，年龄：${info.age}`)
    }else{
        console.log(`我叫：${info.firstName},${info.lastName}，年龄:保密`)
    }  
}

printName({firstName:'lili',lastName:'zhang',age:18,address:'石家庄'})

//函数的类型接口:对函数传入的参数和返回值进行约束--批量约束

interface CompareInterface{
    (first:number,last:number):boolean
}

// function compareFun(first:number,last:number):boolean{
//     return first > last
// }

// let compareFun:CompareInterface =function(first:number,last:number):boolean{
//     return first > last
// }

//简写
// let compareFun:CompareInterface =function(f:number,l:number):boolean{
//     return f > l
// }

//简写

// let compareFun:CompareInterface = function(f,l){
//     return f > l
// }

// compareFun(2,1)

//可索引接口

interface Arr{
    [index:number]:string
}

let arr:Arr = ['str1','str2'];

console.log(arr[1]);

//对象的
interface UserObj {
    [index:string]:string
}

let obj:UserObj = {name:'lili',age:'20'};

console.log(obj.name);
console.log(obj.age);

//类类型接口

interface Animal{
    name:string;
    eat(str:string):void
}

class Dog implements Animal{
    name:string;
    constructor(name:string){
        this.name = name;
    }
    eat(){
        console.log(this.name+'吃肉')
    }
}

let d = new Dog('达摩');
d.eat();

class Cat implements Animal{
    name:string;
    constructor(name:string){
        this.name = name;
    }
    eat(){
        console.log(this.name+'吃鱼')
    }
}

let cat = new Cat('小花');
cat.eat();